package com.cuiweiyou.bluemesh.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.cuiweiyou.bluemesh.base.BluetoothApp;

public class SPDataUtil {
    private static SPDataUtil instance;
    private SharedPreferences sharedPreferences;

    private SPDataUtil() {
        sharedPreferences = BluetoothApp.getContext().getSharedPreferences("mesh_shared_preferences", Context.MODE_PRIVATE);
    }

    public static SPDataUtil getInstance() {
        if (null == instance) {
            synchronized (SPDataUtil.class) {
                if (null == instance) {
                    instance = new SPDataUtil();
                }
            }
        }
        return instance;
    }

    public void saveHometype(boolean isit) {
        SharedPreferences.Editor edit = sharedPreferences.edit();
        edit.putBoolean("is_home_type", isit);
        edit.commit();
    }

    /**
     * @return 默认false
     */
    public boolean isHometype() {
        return sharedPreferences.getBoolean("is_home_type", false);
    }

    public void saveFirstTimeRunApp(boolean isit) {
        SharedPreferences.Editor edit = sharedPreferences.edit();
        edit.putBoolean("is_first_time_run_app", isit);
        edit.commit();
    }

    /**
     * @return 默认true
     */
    public boolean isFirstTimeRunApp() {
        return sharedPreferences.getBoolean("is_first_time_run_app", true);
    }
}
